s = input()
n = int(input())
for i in range(n):
    a, b, c, d = input().split()
    str = s[int(a) - 1:int(b)]
    s = s[:int(a) - 1] + s[int(b):]
    if c + d not in s:
        s += str
    else:
        s = s.replace(c + d, c + str + d, 1)
print(s)
